<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org"
      lang="zh-cn">
<head>
    <meta content="云之讯,云通讯,云通讯平台" name="keywords"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1, maximum-scale=1"/>
    <title>短信平台运营系统 </title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
    <link th:href="@{/resources/css/bootstrap.min14ed.css?v=3.3.6}" rel="stylesheet">
    <link th:href="@{/resources/css/font-awesome.min93e3.css?v=4.4.0}" rel="stylesheet">
    <!-- jqgrid-->
    <link th:href="@{/resources/css/animate.min.css}" rel="stylesheet">
    <link th:href="@{/resources/css/plugins/sweetalert/sweetalert.css}" rel="stylesheet">
    <link th:href="@{/resources/css/select2.css}" rel="stylesheet">
    <link th:href="@{/resources/css/style.min862f.css?v=4.1.0}" rel="stylesheet">
    <style>
        /* Additional style to fix warning dialog position */
        #alertmod_table_list_2 {
            top: 900px !important;
        }
        .pop{
            background-color: #FFF;
            padding:20px;
        }
        .page-title{
            padding: 20px 0;
            position: relative;
            z-index:10;
        }
        .page-title .line{
            position: absolute;
            width:100%;
            height:1px;
            background-color: #DDD;
            left:0;
            top:50%;
        }
        .page-title .title{
            padding-left:5px;
            padding-right:5px;
            border-left:10px solid #0a8000;
            position: relative;
            z-index:11;
            display: inline-block;
            background-color: #FFF;
        }
        .imgupload{
            position: relative;
            width:180px;
            height:180px;
            line-height: 180px;
            text-align: center;
            border:1px solid #DDD;
            overflow: hidden;
        }
        .imgupload span{
            font-size:30px;
        }
        .imgupload input{
            position: absolute;
            opacity: 0;
            top:0;
            left:0;
            width:100%;
            height:100%;
        }
        .imgupload img{
            position: absolute;
            top:0;
            left:0;
            width:100%;
            height:100%;
            z-index:100;
            display: none;
        }
        .red{
            color: red;
        }
        .select2 span{
            display:block !important;
            margin-top: 0px !important;
        }
        .select2-container {
            width: 171px !important;
        }
        .select2-dropdown {
            width: 175px !important;
        }
        .select2-container .select2-selection--single{
            width:175px;
        }
        .hide{
            display: none;
        }
        #success_open {
            text-align: center;
            background-color: #01AAED;
            color: #fff;
            padding: 5px 0;
        }
    </style>
</head>
<body class="gray-bg"><div th:replace="stat :: statCode"></div>
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="tabs-container">
                <input id="smspImgUrl" type="hidden" th:value="${smspImgUrl}">
                <ul class="nav nav-tabs">
                    <li th:if="${menus.zkkh}">
                        <a  href="/accountInfo/client/addzk">直客开户</a>
                    </li>
                    <li class="" th:if="${menus.zzhkh}">
                        <a href="/accountInfo/client/add">子账户开户</a>
                    </li>
                    <li class="active" th:if="${menus.khkh}">
                        <a href="#tab-3" class="active">客户开户</a>
                    </li>
                </ul>
                <div class="tab-pane active" th:if="${menus.khkh}">
                    <div class="panel-body">
                <div class="page-title">
                    <span class="title">基本资料</span>
                    <span class="line"></span>
                </div>
                <div class="form-horizontal m-t" id="mainForm">

                    <div class="form-group">
                        <label class="col-sm-3 control-label"><span style="color: red;">*</span>客户名称:</label>
                        <div class="col-sm-8">
                            <input type="text" class="form-control"  id="company" name="company" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label"><span style="color: red;">*</span>联系地址:</label>
                        <div class="col-sm-8">
                            <input type="text" class="form-control"  id="address" name="address" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label"><span style="color: red;">*</span>邮箱:</label>
                        <div class="col-sm-8">
                            <input type="text" class="form-control"  id="email" name="email" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label"><span style="color: red;">*</span>手机号码:</label>
                        <div class="col-sm-8">
                            <input type="text" class="form-control"  id="mobile" name="mobile" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label"><span style="color: red;">*</span>归属销售:</label>
                        <div class="col-sm-8" style="width: 250px">
                            <select id="belongSale" name="belongSale"  class="form-control"></select>
                            <input type="hidden" name="belongSale" class="js-key js-sale" data-key="belongSale">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label"><span style="color: red;">*</span>登录密码:</label>
                        <div class="col-sm-8">
                            <input type="password" class="form-control"  id="password" name="password" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label"><span style="color: red;">*</span>确认密码:</label>
                        <div class="col-sm-8">
                            <input type="password" class="form-control"  id="confirmpwd" name="confirmpwd" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label"><span class="red">*</span>测试短信赠送:</label>
                        <div class="col-sm-2">
                            <select class="form-control" name="productType" id="productType">
                                <option value="0">行业+全网+全国</option>
                            </select>
                        </div>
                        <div class="col-sm-2">
                            <select class="form-control" name="testProductId" id="testProductId">
                                <option value="">请选择产品</option>
                                <option th:each="product : ${productInfoList}" th:value="${product.product_id}" th:text="${product.product_name}">选项 4</option>
                            </select>
                        </div>
                        <div class="col-sm-2">
                            <input type="text" id="testSmsNumber" name="testSmsNumber" class="form-control" placeholder="请填写赠送的短信条数">
                        </div>

                        <div class="col-sm-1" >
                            <label class="control-label">[0~100]</label>
                        </div>

                    </div>
                    <div class="page-title">
                        <span class="title">资质认证</span>
                        <span class="line"></span>
                    </div>
                    <div class="form-horizontal">
                        <div class="form-group">
                            <label class="col-sm-3 control-label"><span class="red">*</span>证件类型：</label>
                            <div class="col-sm-4">
                                <select class="form-control" name="idType" id="idType">
                                    <option value="3">组织机构证</option>
                                    <option value="4">税务登记证</option>
                                    <option value="5">营业执照</option>
                                    <option value="6">三证合一(企业)</option>
                                    <option value="7">四证合一(企业)</option>
                                    <option value="8">登记证书号</option>
                                    <option value="1">个人身份证</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label"><span class="red">*</span>证件号码：</label>
                            <div class="col-sm-4">
                                <input type="text" class="form-control number" name="idNbr" data-key="idNbr" id="idNbr">
                            </div>
                        </div>
                        <input type="hidden"  id="oauthTypeID"  th:value="${oauthType}" >
                        <div class="form-group">
                            <label class="col-sm-3 control-label"><span class="red">*</span>证件图片：</label>
                            <div class="col-sm-4">
                                <div class="imgupload">
                                    <span class="glyphicon glyphicon-plus"></span>
                                    <img src="" alt="" class="js-img img" id="preview">
                                    <form id="imgForm" enctype="multipart/form-data" method="post">
                                        <input type="file" class="js-file" id="photoFile" accept="image/jpeg,image/jpg,image/gif,image/png" name="photoFile">
                                    </form>
                                </div>
                            </div>
                        </div>
                        <span style="margin-left: 24%;">支持JPG、PNG、GIF格式，文件大小不得大于2M</span>
                    </div>
                    <div class="page-title">
                        <span class="title">代理贴牌</span>
                        <span class="line"></span>
                    </div>
                    <div class="form-group ">
                        <label for="" class="col-sm-3 control-label"><span class="red">*</span>是否贴牌：</label>
                        <div class="col-sm-4">
                            <label class="radio-inline">
                                <input type="radio"  value="1" name="tp"   class="tp"> 是
                            </label>
                            <label class="radio-inline">
                                <input type="radio"  value="0" name="tp" checked  class="tp"> 否
                            </label>
                        </div>
                    </div>
                    <div class="form-group istp">
                        <label class="col-sm-3 control-label">域名:</label>
                        <div class="col-sm-8">
                            <input type="text" class="form-control"  id="domainName" name="domainName" placeholder="例：oemclient.sms.ucpaas.com" value="oemclient.sms.ucpaas.com" th:value="${clientSiteUrl}"/>
                        </div>
                    </div>
                    <div class="form-group istp">
                        <label class="col-sm-3 control-label">版权文字:</label>
                        <div class="col-sm-8">
                            <input type="text" class="form-control" id="copyrightText" name="copyrightText"  placeholder="例：2014-2018 深圳市云之讯网络技术有限公司 粤ICP备14046848号 " value="2014-2018 深圳市云之讯网络技术有限公司 粤ICP备14046848号"/>
                        </div>
                    </div>
                    <div class="form-group istp">
                        <label class="col-sm-3 control-label">导航栏背景色:</label>
                        <div class="col-sm-8">
                            <input type="text" class="form-control" id="navigationBackcolor" name="navigationBackcolor" maxlength="7"  placeholder="例如棕黑色为：#506470" value="#506470"/>
                        </div>
                    </div>
                    <div class="form-group istp">
                        <label class="col-sm-3 control-label">导航栏文字颜色:</label>
                        <div class="col-sm-8">
                            <input type="text" class="form-control" id="navigationTextColor" name="navigationTextColor"  maxlength="7"  placeholder="例如棕黑色为：#506470" value="#506470"/>
                        </div>
                    </div>


                    <input type="hidden" id="tabLogoUrl" name="tabLogoUrl" value=""/>
                    <input type="hidden" id="logoUrl" name="logoUrl" value=""/>
                    <input type="hidden" id="companyLogoUrl" name="companyLogoUrl" value=""/>
                    <input type="hidden" id="apiDocumentUrl" name="apiDocumentUrl" value=""/>
                    <input type="hidden" id="fAQDocumentUrl" name="fAQDocumentUrl" value=""/>

                    <div class="oemInfo istp"> <!-- OEM代理商信息开始 -->
                        <form class="form-horizontal" method="post" id="tab_logo_form">
                            <div class="form-group">
                                <label class="col-sm-3 control-label">标签页图标:<br/> (尺寸：48px*48px)</label>
                                <div class="col-sm-8">
                                    <img id="preview_tab_logo" style="width: 48px;height: 48px;cursor: pointer;" name="preview_tab_logo" class="eg-preview" th:src="@{/resources/img/tab-logo_model.png}" alt="示例：标签图标" />
                                    <br><input type="file" accept="image/x-icon" id="tab_logo" name="tabLogoUrl"/>
                                </div>
                            </div>
                        </form>

                        <form class="form-horizontal istp" method="post" id="logo_form">
                            <div class="form-group">
                                <label class="col-sm-3 control-label">LOGO图:<br/> (尺寸：41px*43px)</label>
                                <div class="col-sm-8">
                                    <img id="preview_logo" class="eg-preview" style="width: 41px;height: 43px;cursor: pointer;" th:src="@{/resources/img/logo_model.png}" alt="示例：logo"/>
                                    <br><input type="file" accept="image/png" id="logo" name="logoUrl"/>
                                </div>
                            </div>
                        </form>



                        <form class="form-horizontal istp" method="post" id="company_logo_form">
                            <div class="form-group">
                                <label class="col-sm-3 control-label">LOGO + 公司名称图:<br/> (尺寸：184px*30px)</label>
                                <div class="col-sm-8">
                                    <img id="preview_company_logo" class="eg-preview" style="width: 184px;height: 30px;cursor: pointer;" th:src="@{/resources/img/logo-company_model.png}" alt="示例：logo+公司名"/>
                                    <br><input type="file" id="company_logo" name="companyLogoUrl" accept="image/png" />
                                </div>
                            </div>
                        </form>
                        <form class="form-horizontal istp" method="post" id="api_document_Form">
                            <div class="form-group">
                                <label class="col-sm-3 control-label">接口文档<br/>(文件不大于5MB):</label>
                                <div class="col-sm-8">
                                    <input type="file"  class="form-control" id="api_document" name="apiDocumentUrl" accept="application/vnd.openxmlformats-officedocument.wordprocessingml.document" />
                                </div>
                            </div>
                        </form>
                        <form class="form-horizontal istp" method="post" id="FAQ_document_Form">
                            <div class="form-group">
                                <label class="col-sm-3 control-label">FAQ文档<br/>(文件不大于5MB):</label>
                                <div class="col-sm-8">
                                    <input type="file"  class="form-control" id="FAQ_document" name="fAQDocumentUrl" accept="application/vnd.openxmlformats-officedocument.wordprocessingml.document" />
                                </div>
                            </div>
                        </form>


                    </div><!-- OEM代理商信息结束-->

                    <form class="form-horizontal">
                        <div class="form-group">
                            <label  class="col-sm-3 control-label">备注：</label>
                            <div class="col-sm-4">
                                <input type="text" name="remark" id="remark" class="form-control js-key" data-key="remark">
                            </div>
                        </div>
                    </form>

                    <form class="form-horizontal" >
                        <div class="form-horizontal">
                            <div class="col-sm-12 col-sm-offset-3">
                                <button type="button" class="btn btn-sm btn-success" onclick="uploadData(this)">完成开户</button>
                                <!--<button type="button" class="btn btn-sm btn-error" onclick="goback()">取消</button>-->
                            </div>
                        </div>
                    </form>
                </div>
            </div>
                </div>
            </div>
        </div>
    </div>
</div>
<div id="pop" class="pop" style="display: none;">
    <p id="success_open">成功开户，请联系客服审核资质！</p>
    <div id="copyContent">
        <h3>用户中心自助管理平台（管理多个子账户）</h3>
        <p>网址：<span class="agentLoginUrl"></span></p>
        <p>登录账户：<span class="text-agent"></span></p>
        <p>绑定邮箱：<span class="text-email"></span>（可用于登录）</p>
        <p>绑定手机：<span class="text-mobile"></span>（可用于登录）</p>
        <p>登录密码：<span class="text-pwd"></span></p>
    </div>
    <div style="text-align: center">
        <!-- <h3 class="isagentOwned ktmsg">开户成功，是否马上资质认证</h3>-->
        <a href="javascript:;" class="btn btn-success copyContent" style="margin-right: 40px;" data-clipboard-target="#copyContent">复制</a>
        <!--<a href="javascript:;" class="btn btn-success redirect isagentOwned ktmsg" >子账户资质认证</a>-->
        <a href="/agentInfo/add" class="btn btn-default J_menuItem">关闭</a>
    </div>

</div>
<script th:src="@{/resources/js/hex_ha_ha_ha_ha_ha.js}"></script>
<script th:src="@{/resources/js/jquery.min.js?v=2.1.4}"></script>
<script th:src="@{/resources/js/bootstrap.min.js?v=3.3.6}"></script>
<script th:src="@{/resources/js/plugins/peity/jquery.peity.min.js}"></script>
<script th:src="@{/resources/js/content.min.js?v=1.0.0}"></script>
<script th:src="@{/resources/js/date_format.min.js?v=1.0.0}"></script>
<script th:src="@{/resources/js/jquery.form.js?v=1.0.0}"></script>
<script th:src="@{/resources/js/plugins/sweetalert/sweetalert.min.js}"></script>
<script th:src="@{/resources/js/plugins/validate/jquery.validate.min.js}"></script>
<script th:src="@{/resources/js/layer/layer.js}"></script>
<script th:src="@{/resources/js/smsp.validate.js}"></script>
<script th:src="@{/resources/js/common.js?v=1.0.0}"></script>
<script th:src="@{/resources/js/auth.js?v=1.0.0}"></script>
<script th:src="@{/resources/js/clipboard.min.js?v=1.0.0}"></script>
<script th:src="@{/resources/js/addClient.js?v=3.8.10}"></script>
<script th:src="@{/resources/js/select2.min.js}"></script>
<script th:inline="javascript">
    /*<![CDATA[*/

    //msg消失时间
    var msgTime = 1500;
    var isOem = true;
    var isBrand = false;

    //重复提交
    var repeatSubmit = false;
    var img_url = [[${smsp_img_url}]];
    var urlPath;
    $(function(){
        var clipboard = new Clipboard('.copyContent');
        clipboard.on('success', function (e) {
            layer.msg("复制成功", {time: 1000})
        });
        clipboard.on('error', function (e) {
            layer.msg("复制失败，复制功能只支持 Chrome 42+、Firefox 41+、IE 9+、Opera 29+", {time: 3000})
        });
        $('input[type="file"]').change(function() {
            var $file = $(this);
            var id = $file.attr("id");
            var fileObj = $file[0];
            var windowURL = window.URL || window.webkitURL;
            var dataURL;
            var $img = $("#preview_" + id);
            if(fileObj && fileObj.files && fileObj.files[0]){
                dataURL = windowURL.createObjectURL(fileObj.files[0]);
                fileUrl = fileObj.files[0];
                $img.attr('src',dataURL);
            }else{
                dataURL = $file.val();
                fileObj.files[0] = fileUrl;
                var imgObj = document.getElementById("preview_" + id);
            }
        });



        //是否贴牌
        $("input:radio[name='tp']").click(function () {
            if($(this).val() == '0'){
                $(".istp").hide()
            }else {
                $(".istp").show()
            }
        })

        //是否开通子账户
        $("input:radio[name='kt']").click(function () {
            if($(this).val() == '0'){
                $(".iskt").hide()
            }else {
                $(".iskt").show()
            }
        })
        if($("input:radio[name='kt']:checked").val() == '0'){
            $(".iskt").hide()
        }else {
            $(".iskt").show()
        }
        if($("input:radio[name='tp']:checked").val() == '0'){
            $(".istp").hide()
        }else {
            $(".istp").show()
        }
        $(".imgupload").click(function(){
//            $(".js-file").trigger("click");
        })

        $("#smsfrom").click(function(){
            //http和sgip出现的东西不一样
            if($("#smsfrom").val() == 6){
                $(".grid-sgip").addClass("hide");
                $(".grid-sgip").find("input").val("");
                $(".grid-https").removeClass("hide");
            } else if($("#smsfrom").val() == 4){
                $(".grid-https").addClass("hide");
                $(".grid-https").find('input').val("");

                $(".grid-sgip").removeClass("hide");
            } else {
                $(".grid-https").addClass("hide");
                $(".grid-sgip").addClass("hide");

                $(".grid-https").find('input').val("");
                $(".grid-sgip").find("input").val("");
            }
        })


        //选择图片
        $(".js-file").change(function() {

            var $file = $(this);
            var fileObj = $file[0];
            var windowURL = window.URL || window.webkitURL;
            var dataURL;
            var $img = $("#preview");
            if(fileObj && fileObj.files && fileObj.files[0]){
                dataURL = windowURL.createObjectURL(fileObj.files[0]);
                fileUrl = fileObj.files[0];
                $img.attr('src',dataURL);
            }

            uplaodImg()
        });
        //图片上传
        function uplaodImg(){

            var options = {
                url : img_url +  "/upload/uploadAuto.html",
                data:{
                    idType:$("#oauthTypeID").val()
                },
                beforeSubmit: function(){
                    ityzl_SHOW_LOAD_LAYER("正在上传图片，请勿刷新页面...");
                },
                success : function(data) {
                    layer.closeAll(); //疯狂模式，关闭所有层
                    picUploadStatus = 1;
                    if(data == ""){	//session超时
                        return;
                    }
                    if (data.result == null) {
                        layer.alert("服务器错误，请联系管理员", {
                            icon : 2
                        });
                        return;
                    } else if (data.result == "success") {
                        layer.msg('<p style="color:black">'+data.msg+'</p>', {
                            icon : 1
                        });
                        $(".js-img").attr("path", img_url +data.path);
                        urlPath = data.path;

                        $(".js-img").show();
                    } else if(data.reusult == "none"){
                        layer.msg('<p style="color:black">'+data.msg+'</p>', {icon : 0},function(){

                        });
                    }else{
                        layer.msg('<p style="color:black">'+data.msg+'</p>', {icon:2},function(){

                        });
                    }
                },
                error: function (error) {
                    layer.closeAll(); //疯狂模式，关闭所有层
                    layer.alert('服务器正忙，请稍后再试', {icon: 2});
                },
                dataType:"json",
                type : "post",
                timeout : 600000
            };
            $("#imgForm").ajaxSubmit(options);
        }

        //保存资质
        $(".js-save").click(function(){
            document.getElementById("saveID").setAttribute("disabled", true);
            var clientType = $("#oauthTypeID").val();
            var idNbr = $(".number").val();
            var imgurl = urlPath;
            var realName = $("#nameID").text();
            var idType =$("#idType").val();
            var agentId = $("#agentId").text();
            $.ajax({
                url:/*[[@{/accountInfo/qualification/save}]]*/,
                type:"POST",
                data:{
                    idNbr: idNbr,
                    imgurl:imgurl,
                    realName:realName,
                    idType: idType,
                    clientType:clientType,
                    agentId:agentId
                },
                success:function(data){
                    // document.getElementById("saveID").removeAttribute("disabled");
                    if(data == null){
                        swal("失败！", "系统错误，请稍后再试！", "error")
                        document.getElementById("saveID").removeAttribute("disabled");
                    }else if(data.code == 0){

                        layer.msg(data.msg,{icon:1,time:1500},function () {
                            window.location.href = '/accountInfo/agentmanage'
                        })
                    }else{
                        swal("失败！", data.msg, "error")
                        document.getElementById("saveID").removeAttribute("disabled");
                    }
                }
            })
        });
    })

    function uploadForm(fieldId,url,field,agentInfo){

        var $fieldId = $('#'+fieldId);
        if(!$fieldId.val()){
            //文件不存在不用上传
            return true;
        }
        var uploadFlag = false;
        var options = {
            url:url,
            async: false,
            success : function(data) {
                if(data == "" || data == null || data.result == null) {
                    layer.alert("服务器错误，请联系管理员", {
                        icon : 2
                    });
                }else if (data.result == "success") {
                    $("#"+field).val(data.path1);
                    agentInfo[field] = data.path1;
                    uploadFlag = true;
                }
            },

            type : "post",
            dataType: 'json',
            timeout : 10000
        };
        $($fieldId.parents('form')[0]).ajaxSubmit(options);
        return uploadFlag;
    }

    var maxsize = 5*1024*1024;//2M
    var errMsg = "上传的附件文件不能超过5M！！！";
    var browserCfg = {};
    var fileFlag = false;
    function checkFile(id,tipMsg){
        var ua = window.navigator.userAgent;
        if (ua.indexOf("MSIE")>=1){
            browserCfg.ie = true;
        }else if(ua.indexOf("Firefox")>=1){
            browserCfg.firefox = true;
        }else if(ua.indexOf("Chrome")>=1){
            browserCfg.chrome = true;
        }
        fileFlag = false;
        var file = $("#"+id);

        if (file.val() == ''){
            fileFlag = true;
            return fileFlag;
        }

        var filesize = 0;
        if(browserCfg.firefox || browserCfg.chrome ){
            filesize = file[0].files[0].size;
        }else if(browserCfg.ie){
            fileFlag = false;
            var obj_file = $("#"+id);
            obj_file.dynsrc=file.value;
            filesize = obj_img.fileSize;
        }else{
            fileFlag = true;
            return fileFlag;
        }

        if (filesize == 0) {
            layer.msg('<p style="color:black">选择需要上传的：'+tipMsg+'</p>', {
                icon : 2
            });
            return fileFlag
        } else if (filesize > maxsize) {
            layer.alert(errMsg, {
                icon : 2
            });
            return fileFlag;
        } else {
            fileFlag = true;
            return fileFlag;
        }
    }


    var agentfields = {'company':'代理商名称','address':'联系地址','email':'邮箱','mobile':'手机','belongSale':'归属销售','remark':'备注'};

    function constructAndValidate(agentInfo){
        for(var key in agentfields){
            var value = agentfields[key];
            agentInfo[key] = $('#'+key).val();
            if(!agentInfo[key]&&key!='remark'){
                layer.msg(value+"不能为空！", {icon: 2,time: msgTime});
                return false;
            }

            if(key == "company"){
                if(agentInfo[key].length > 50){
                    layer.msg("代理商名称不能超过50个字符", {icon: 2,time: msgTime});
                    return false;
                }
            }
            if(key == "address"){
                if(agentInfo[key].length > 60){
                    layer.msg("联系地址不能超过60个字符", {icon: 2,time: msgTime});
                    return false;
                }
            }

            if(key == "email"){
                if(!Validate.isValidEmail(agentInfo[key])){
                    layer.msg("请输入合法的邮箱地址", {icon: 2,time: msgTime});
                    return false;
                }
            }
            if(key == "email"){
                if(agentInfo[key].length > 100){
                    layer.msg("邮箱不能超过100个字符", {icon: 2,time: msgTime});
                    return false;
                }
            }

            if(key == "mobile"){
                if(!Validate.isValidMobile(agentInfo[key])){
                    layer.msg("请输入合法的手机号码", {icon: 2,time: msgTime});
                    return false;
                }
            }
            if(key == "mobile"){
                if(agentInfo[key].length > 11){
                    layer.msg("请输入11位有效手机号码", {icon: 2,time: msgTime});
                    return false;
                }
            }
            if(key == "remark"){
                if(agentInfo[key].length > 100){
                    layer.msg("备注不能超过100个字符", {icon: 2,time: msgTime});
                    return false;
                }
            }
        }
        return true;
    }

    function uploadData(btn) {

        var addUrl =  /*[[@{/agentInfo/add}]]*/;
        var upLoadUrl = $("#smspImgUrl").val() + "/upload/multiUpload.html";

        var agentInfo = {};

        if(!constructAndValidate(agentInfo)){
            return;
        }
        var oemfields = {'company':'代理商名称','address':'联系地址','email':'邮箱','mobile':'手机','belongSale':'归属销售','remark':'备注'};
        if(isOem){
            //校验测试产品
            var testProductId = $("#testProductId").val();
            var testSmsNumber = $("#testSmsNumber").val();
            var paytype = $("input[name='paytype']:checked").val();
            var kt = $("input[name='kt']:checked").val();
            var tp = $("input[name='tp']:checked").val();
            var needextend = $("input[name='needextend']:checked").val();

            var needextend = $("input[name='needextend']:checked").val();
            //增加价格字段
            var userPriceList = [];
            $(".js-price").each(function(i){
                var obj = {};
                if($(this).val() != ""){
                    obj.smstype = $(this).attr("smstype");
                    obj.userPrice = $(this).val();
                    userPriceList.push(obj);
                }
            })
            //短信单价和类型的处理
            var yz_price = $(".yz-price").val(),
                tz_price = $(".tz-price").val(),
                yx_price = $(".yx-price").val();
            var params = {};
            $(".js-key").each(function(){
                var value = $(this).val();
                var key   = $(this).data("key");
                params[key] = value;
            })


            //http
           /* if(params.smsfrom == 6 && params.httpProtocolType != 2){
                if(params.paytype == 1){
                    var flag = false;
                    $(".js-price").each(function(){
                        var price = $(this).val();
                        var tip   = $(this).data("str");
                        if(!_Auth.isPrice(price)){
                            flag = true;
                            layer.msg(tip + '格式为0-1之间的小数，最多保留四位小数', {icon: 2});
                            return false;
                        } else {
                            flag = false;
                        }
                    })
                    if(flag){
                        return;
                    }
                }

                //清空短信类型 https默认所有短信类型
                params.smstype = "";
                //清空选择SGIP的三个必填字段
                params.moip   = "";
                params.moport = "";
                params.nodeid = "";
            } else {
                if(params.smsfrom == 6){
                    params.smstype = $(".jsmstype").val();
                }else {
                    params.smstype = $(".js-smstype").val();
                }
                if(_Auth.isNull(params.smstype)){
                    layer.msg('请选择短信类型', {icon: 2});
                    return;
                }
                if(params.smstype == "0" && !_Auth.isPrice(tz_price) && params.paytype == 1){
                    layer.msg('通知短信单价格式为0-1之间的小数，最多保留四位小数', {icon: 2});
                    return;
                }
                if(params.smstype == 5 && !_Auth.isPrice(yx_price) && params.paytype == 1){
                    layer.msg('营销短信单价格式为0-1之间的小数，最多保留四位小数', {icon: 2});
                    return;
                }
                if(params.smstype == 4 && !_Auth.isPrice(yz_price ) && params.paytype == 1){
                    layer.msg('验证码短信单价格式为0-1之间的小数，最多保留四位小数', {icon: 2});
                    return;
                }
            }*/
            agentInfo.userPriceList = userPriceList;

            if(needextend == '1'){
                agentInfo.extendSize = $("#extendSize").val();
            }

            if(tp == '1'){
                agentInfo.hySmsDiscount = $("#hySmsDiscount").val();
                agentInfo.yxSmsDiscount = $("#yxSmsDiscount").val();
                agentInfo.gjSmsDiscount = $("#gjSmsDiscount").val();
                agentInfo.domainName = $("#domainName").val();
                agentInfo.copyrightText = $("#copyrightText").val();
                agentInfo.navigationBackcolor = $("#navigationBackcolor").val();
                agentInfo.navigationTextColor = $("#navigationTextColor").val();
                if(!agentInfo.domainName){
                    layer.msg("域名不能为空", {icon: 2,time: msgTime});
                    return false;
                }
                if(!agentInfo.copyrightText){
                    layer.msg("版权文字不能为空", {icon: 2,time: msgTime});
                    return false;
                }
                if(!agentInfo.navigationBackcolor){
                    layer.msg("导航栏背景色不能为空", {icon: 2,time: msgTime});
                    return false;
                }
                if(!agentInfo.navigationTextColor){
                    layer.msg("导航栏文字颜色不能为空", {icon: 2,time: msgTime});
                    return false;
                }

                if(agentInfo.domainName.length >200){
                    layer.msg("域名不能超过200个字符", {icon: 2,time: msgTime});
                    return false;
                }
                if(agentInfo.copyrightText.length >200){
                    layer.msg("版权文字不能超过200个字符", {icon: 2,time: msgTime});
                    return false;
                }
            }

            if(kt == '1'){
//                agentInfo.clientInfoExt = {extValue: kt};
                agentInfo.paytype = paytype;
                agentInfo.name = $("#name").val();
                agentInfo.chargeRule = $("#chargeRule").val();
                if(agentInfo.chargeRule != 0){
                    agentInfo.autoReturn = $("#autoReturn").val();
                }
                agentInfo.agentOwned = $("#agentOwned").val();
                agentInfo.smsfrom = $("#smsfrom").val();
                if(agentInfo.smsfrom == 4){
                    agentInfo.moip = $("#moip").val();
                    agentInfo.moport = $("#moport").val();
                    agentInfo.nodeid = $("#nodeid").val();
                }
                if(agentInfo.smsfrom == 6){
                    agentInfo.smstype = $(".jsmstype").val();
                }else {
                    agentInfo.smstype = $(".js-smstype").val();
                }
                agentInfo.httpProtocolType = $("#smsHttp").val();
                agentInfo.needmo = $("#needmo").val();
                agentInfo.needreport = $("#needreport").val();
                agentInfo.ip = $("#ip").val();
                agentInfo.needextend = needextend;
                agentInfo.remark = $("#remark").val();
                agentInfo.mourl = $("#mourl").val();
                agentInfo.deliveryurl = $("#deliveryurl").val();
                agentInfo.noticeurl = $("#noticeurl").val();


            }else {
                //agentInfo.clientInfoExt = {extValue: "0"};
            }
            /*需要校验的数据*/
            agentInfo.password = $("#password").val();
            agentInfo.idType = $("#idType").val();
            agentInfo.idNbr = $("#idNbr").val();

            agentInfo.imgUrl = urlPath;
            if(agentInfo.needmo == 1  &&  _Auth.isNull(agentInfo.mourl) && agentInfo.smsfrom == 6){
                layer.msg('请填写上行回调地址', {icon: 2});
                return;
            }
            if((agentInfo.needreport == 1 || agentInfo.needreport == 2) && _Auth.isNull(agentInfo.deliveryurl) && agentInfo.smsfrom == 6){
                layer.msg('请填写状态报告回调地址', {icon: 2});
                return;
            }
            //agentInfo.imgUrl ="NoticeService.jpg";
            if(!agentInfo.password){
                layer.msg("密码不能为空", {icon: 2,time: msgTime});
                return false;
            }
            if(!agentInfo.idType){
                layer.msg("证件类型不能为空", {icon: 2,time: msgTime});
                return false;
            }
            if(!agentInfo.idNbr){
                layer.msg("证件号码不能为空", {icon: 2,time: msgTime});
                return false;
            }


            if(testProductId){
                if(!testSmsNumber){
                    layer.msg("请输入赠送数量！", {icon: 2,time: msgTime});
                    return ;
                }

                var pattern = /^[0-9]*$/;//正整数
                if(!pattern.test(testSmsNumber)){
                    layer.msg("赠送数量只能是[0~100]的正整数！", {icon: 2,time: msgTime});
                    $("#testSmsNumber").val('');
                    return;
                }


                if(testSmsNumber < 0 || testSmsNumber >100){
                    layer.msg("赠送数量只能是[0~100]的正整数！", {icon: 2,time: msgTime});
                    $("#testSmsNumber").val('');
                    return;
                }
                agentInfo.testProductId = testProductId;
                agentInfo.testSmsNumber = testSmsNumber;
            }

            if (!checkFile("tab_logo","标签页图标")||//
                !checkFile("logo","LOGO图")||//
                !checkFile("company_logo","LOGO + 公司名称图")||//
                !checkFile("api_document","接口文档")||//
                !checkFile("FAQ_document","FAQ文档")) {
                return;
            }

            ityzl_SHOW_LOAD_LAYER("资料上传中,请稍后...");
            if (!uploadForm("tab_logo", upLoadUrl, "tabLogoUrl",agentInfo)||//
                !uploadForm("logo", upLoadUrl, "logoUrl",agentInfo)||//
                !uploadForm("company_logo", upLoadUrl,"companyLogoUrl",agentInfo)||//
                !uploadForm("api_document", upLoadUrl,"apiDocumentUrl",agentInfo)||//
                !uploadForm("FAQ_document", upLoadUrl,"fAQDocumentUrl",agentInfo)) {
                return;
            };

            if(tp == '1'){
                fillOEMInfo(agentInfo);
            }
        }
        if(repeatSubmit){
            layer.msg("请勿重复提交", {icon: 2,time: msgTime});
        }else{
            repeatSubmit = true;
        }

        $.ajax({
            type:"POST",
            //提交的网址
            url:addUrl,
            data:JSON.stringify(agentInfo),
            //请求数据的格式
            contentType: "application/json; charset=utf-8",
            //返回数据的格式
            datatype: "json",
            //成功返回之后调用的函数
            success:function(result){
                repeatSubmit = false;
                if(result.code == 0){
                    //填充数据
                    $(".text-agent").text(result.data.agentId);
                    $(".text-email").text(result.data.email);
                    $(".text-mobile").text(result.data.mobile);
                    $(".text-pwd").text(result.data.password);
                    $(".agentLoginUrl").text(result.data.agentLoginUrl);
                    $(".agentId").text(result.data.agentId);
                    $(".clientUrl").text(result.data.clientUrl);
                    $(".clientId").text(result.data.clientId);
                    $(".interfaceClientId").text(result.data.interfaceClientId);
                    $(".interfacePassword").text(result.data.interfacePassword);


                    $(".redirect").attr("href", "/accountInfo/qualification/save?clientid=" + result.data.clientId);
                    layer.closeAll();
                    if(kt == '0'){
                        layer.msg(result.msg,{time:1500},function () {
                            window.location.href = '/accountInfo/agent/query'
                        });
                    }else {
                        layer.open({
                            type: 1,
                            title:'<p style="text-align: center">开户信息</p>',
                            skin: 'layui-layer-rim', //加上边框
                            area: ['420px', 'auto'], //宽高
                            content: $(".pop"),
                            cancel:function () {
                                window.location.reload();
                            }
                        });
                        if(agentInfo.agentOwned == '1'){
                            $(".isagentOwned").hide()
                        }else {
                            $(".isagentOwned").show()

                        }
                    }


//            		 layer.msg(result.msg, {icon: 1, time: 1500}, function () {
//                         var mainUrl = /*[[@{/accountInfo/agent/query}]]*/'';
//                         window.location.href = mainUrl;
//                     });
                }else{
                    if(result&&result.msg){
                        layer.msg(result.msg, {icon: 2,time: msgTime});
                    }else{
                        layer.msg("服务器异常，请联系管理员处理", {icon: 2,time: msgTime});
                    }
                }
            },
            //调用执行后调用的函数
            complete: function(XMLHttpRequest, textStatus){
                repeatSubmit = false;
            },
            //调用出错执行的函数
            error: function(){
                repeatSubmit = false;
            }
        });


    }


    function fillOEMInfo(agentInfo){
        if(!agentInfo.domainName){
            agentInfo.domainName = 'oemclient.sms.ucpaas.com';
        }
        if(!agentInfo.copyrightText){
            agentInfo.copyrightText = '2014-2018 深圳市云之讯网络技术有限公司 粤ICP备14046848号';
        }
        if(!agentInfo.navigationBackcolor){
            agentInfo.navigationBackcolor = '#506470';
        }
        if(!agentInfo.navigationTextColor){
            agentInfo.navigationTextColor = '#506470';
        }
        if(!agentInfo.hySmsDiscount){
            agentInfo.hySmsDiscount = 1;
        }
        if(!agentInfo.yxSmsDiscount){
            agentInfo.yxSmsDiscount = 1;
        }
        if(!agentInfo.gjSmsDiscount){
            agentInfo.gjSmsDiscount = 1;
        }
    }

    function goback(){
        window.location.href= /*[[@{/accountInfo/agent/query}]]*/;
    }

    //loading 效果
    function ityzl_SHOW_LOAD_LAYER(msg){
        return layer.msg('<div style="color:#506470;font-family: "microsoft yahei","Arial Narrow",HELVETICA;">'+msg+'</div>', {icon: 16,shade: [0.5, '#f5f5f5'],scrollbar: false,offset: 'auto',time: 600000}) ;
    }

    function agentTypeOnChange(agentType){
        if(agentType==2){
            isOem = false;
            isBrand = true;
            $(".oemInfo").hide();
        }
        if(agentType==5){
            isOem = true;
            isBrand = false;
            $(".oemInfo").show();
        }

    }
    /*]]>*/

</script>
</body>
</html>